Skip to content

feat: Implemet from_protobuf for the token_lifecycle transaction - #2791

Open
manishdait wants to merge 5 commits into
hiero-ledger:mainfrom
manishdait:chore/token-lifecycle-from-protobuf
Open

manishdait wants to merge 5 commits into
hiero-ledger:mainfrom
manishdait:chore/token-lifecycle-from-protobuf

Conversation

@manishdait

Copy link
Copy Markdown
Contributor

Description:
This PR introduce implementation for the _from_protobuf method for the token lifecycle transaction.

Related issue(s):

Fixes #2616

Notes for reviewer:

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

@github-actions github-actions Bot added approved Issue has been approved by team member lang: python Uses Python programming language skill: advanced requires knowledge of multiple areas in the codebase without defined steps to implement or examples labels Nov 13, 2026
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.43590% with 2 lines in your changes missing coverage. Please review.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2791      +/-   ##
==========================================
+ Coverage   96.06%   96.11%   +0.04%     
==========================================
  Files         175      175              
  Lines       11851    11929      +78     
==========================================
+ Hits        11385    11465      +80     
+ Misses        466      464       -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@manishdait
manishdait force-pushed the chore/token-lifecycle-from-protobuf branch from f6997e2 to 8ea80da Compare November 17, 2026 11:26
@manishdait
manishdait marked this pull request as ready for review November 17, 2026 11:28
@manishdait
manishdait requested review from a team as code owners November 17, 2026 11:28
@github-actions github-actions Bot added open to community review PR is open for community review and feedback queue:junior-committer PR awaiting initial quality review labels Nov 17, 2026
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

Five token transaction classes now restore type-specific fields from protobuf bodies. Supply and token type enums convert protobuf values to SDK members. Unit and integration tests cover deserialization, byte round trips, and execution of reconstructed transactions.

Changes

Token transaction deserialization

Layer / File(s) Summary
Token creation deserialization and enum conversion
src/hiero_sdk_python/tokens/supply_type.py, src/hiero_sdk_python/tokens/token_type.py, src/hiero_sdk_python/tokens/token_create_transaction.py, tests/unit/supply_type_test.py, tests/unit/token_type_test.py, tests/unit/token_create_transaction_test.py, tests/integration/token_create_transaction_e2e_test.py
Supply and token type enums convert protobuf values to SDK members. Token creation deserialization restores parameters and keys. Tests cover populated and default values, byte round trips, and execution of reconstructed fungible and non-fungible token creation transactions.
Token and NFT update deserialization
src/hiero_sdk_python/tokens/token_update_transaction.py, src/hiero_sdk_python/tokens/token_update_nfts_transaction.py, tests/unit/token_update_transaction_test.py, tests/unit/token_update_nfts_transaction_test.py, tests/integration/token_update_transaction_e2e_test.py, tests/integration/token_update_nfts_transaction_e2e_test.py
Token update and NFT update deserialization restore fields from protobuf bodies. Unit tests cover populated and absent data and byte round trips. Integration tests execute reconstructed transactions and verify updated token or NFT data.
Token deletion and fee schedule deserialization
src/hiero_sdk_python/tokens/token_delete_transaction.py, src/hiero_sdk_python/tokens/token_fee_schedule_update_transaction.py, tests/unit/token_delete_transaction_test.py, tests/unit/token_fee_schedule_update_transaction_test.py, tests/integration/token_delete_transaction_e2e_test.py, tests/integration/token_fee_schedule_update_transaction_e2e_test.py
Token deletion and fee schedule update deserialization restore fields from protobuf bodies. Unit tests cover populated and absent data and byte round trips. Integration tests execute reconstructed transactions and verify token state or fees.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Severity of issue fixed: Medium

Merge Risk: Low · up to 4a06d

Token lifecycle transactions can now be restored from protobuf bodies. A few edge cases remain: a missing treasury is replaced with a default account, and absent or empty metadata and memo may not round-trip identically. These affect narrow edge cases and test hygiene rather than the main flows, so the change is mergeable with follow-up.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive [#2616] Requires _from_protobuf for TokenCreate, TokenUpdate, TokenDelete, TokenUpdateNfts, and TokenFeeScheduleUpdate, plus removal of xfail markers in the #2614 round-trip harness. The whole-PR … Confirm that TokenCreateTransaction.build_transaction_body() emits treasury only when set. If it does not, make the restored treasury None when treasury is absent, and confirm that the round trip keeps to_bytes() byte-identical. Con…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title names the main change: adding a _from_protobuf implementation for token lifecycle transactions. The raw summary shows _from_protobuf added to TokenCreate, TokenUpdate, TokenDelete, Token…
Description check Passed The description states the PR adds the _from_protobuf method for token lifecycle transactions. It links issue #2616 and says tests and docs were done. This matches the changeset, though it gives lit…
Out of Scope Changes check Passed The change set stays within the issue scope. TokenType._from_proto and SupplyType._from_proto are enum converters that the token create restoration needs. Each _from_protobuf is limited to its t…
Full details: Title check

Explanation

The title names the main change: adding a _from_protobuf implementation for token lifecycle transactions. The raw summary shows _from_protobuf added to TokenCreate, TokenUpdate, TokenDelete, TokenUpdateNfts, and TokenFeeScheduleUpdate transactions, so the title matches the changeset. It is a partial match in scope, since it says 'token_lifecycle' rather than naming the five classes. The title has a typo: 'Implemet' should be 'Implement'.

Full details: Description check

Explanation

The description states the PR adds the _from_protobuf method for token lifecycle transactions. It links issue #2616 and says tests and docs were done. This matches the changeset, though it gives little detail on which transaction classes are covered.

Full details: Out of Scope Changes check

Explanation

The change set stays within the issue scope. TokenType._from_proto and SupplyType._from_proto are enum converters that the token create restoration needs. Each _from_protobuf is limited to its token transaction class. The integration and unit tests cover the new deserialization paths. No unrelated public API signature change is reported. The change summary lists no changes to declarations of exported or public entities.

Full details: Linked Issues check

Explanation

[#2616] Requires _from_protobuf for TokenCreate, TokenUpdate, TokenDelete, TokenUpdateNfts, and TokenFeeScheduleUpdate, plus removal of xfail markers in the #2614 round-trip harness. The whole-PR diff of token_create_transaction.py adds _from_protobuf that calls super()._from_protobuf, restores fields from tokenCreation, and uses HasField for optional keys and fields. The change summary reports equivalent _from_protobuf methods for the other four classes and unit tests for each. Two points remain unresolved. (1) For treasury, the implementation substitutes AccountId(0, 0, 1) when the field is absent. The issue requires unset optional fields to stay None. The build-body logic that decides whether treasury is emitted was not inspected, so it is unknown whether this substitution breaks the round trip or byte-identical to_bytes(). (2) No change to a #2614 round-trip harness file appears in the change summary. Whether #2614 is merged, and whether the xfail markers exist in this repository, was not established.

Resolution

Confirm that TokenCreateTransaction.build_transaction_body() emits treasury only when set. If it does not, make the restored treasury None when treasury is absent, and confirm that the round trip keeps to_bytes() byte-identical. Confirm the state of #2614 and, if the harness is present, remove the xfail markers for the five types or state that the harness is not yet merged.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (2)

Major · Keep absent NFT metadata absent when rebuilding. · token_update_nfts_transaction.py:116

src/hiero_sdk_python/tokens/token_update_nfts_transaction.py:116
Major · Data Integrity & Integration · Quick win

Keep absent NFT metadata absent when rebuilding.

Proto field: metadata #3. Issue type: Asymmetric round-trip.

If the input omits metadata, the new deserializer retains None. This builder still creates a BytesValue message. In the supported protobuf Python implementation, value=None produces an empty wrapper, which becomes present in the parent message. Rebuilding therefore changes “leave metadata unchanged” into “clear metadata.” (raw.githubusercontent.com)

Suggested fix

-            metadata=BytesValue(value=self.metadata),
+            metadata=BytesValue(value=self.metadata) if self.metadata is not None else None,

As per path instructions, “No silent divergence in semantics.”

Source: Path instructions

Minor · Preserve explicitly empty update wrappers when rebuilding. · token_update_transaction.py:421-422

src/hiero_sdk_python/tokens/token_update_transaction.py:421-422
Minor · Data Integrity & Integration · Quick win

Preserve explicitly empty update wrappers when rebuilding.

Proto fields: memo #13 and metadata #16. Issue type: Asymmetric round-trip.

The new deserializer restores present empty wrappers as "" and b"". These truthiness checks then omit both fields. An unfrozen round trip changes a clearing request into a request that leaves the existing values unchanged. Use is not None to preserve presence. (raw.githubusercontent.com)

Suggested fix

-            memo=StringValue(value=self.token_memo) if self.token_memo else None,
-            metadata=BytesValue(value=self.metadata) if self.metadata else None,
+            memo=StringValue(value=self.token_memo) if self.token_memo is not None else None,
+            metadata=BytesValue(value=self.metadata) if self.metadata is not None else None,

As per path instructions, “Every field parsed in _from_proto SHOULD also be serialized in _to_proto.”

Source: Path instructions

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ee40221 and 8ea80da.

Files selected for processing: 19

  • src/hiero_sdk_python/tokens/supply_type.py
  • src/hiero_sdk_python/tokens/token_create_transaction.py
  • src/hiero_sdk_python/tokens/token_delete_transaction.py
  • src/hiero_sdk_python/tokens/token_fee_schedule_update_transaction.py
  • src/hiero_sdk_python/tokens/token_type.py
  • src/hiero_sdk_python/tokens/token_update_nfts_transaction.py
  • src/hiero_sdk_python/tokens/token_update_transaction.py
  • tests/integration/token_create_transaction_e2e_test.py
  • tests/integration/token_delete_transaction_e2e_test.py
  • tests/integration/token_fee_schedule_update_transaction_e2e_test.py
  • tests/integration/token_update_nfts_transaction_e2e_test.py
  • tests/integration/token_update_transaction_e2e_test.py
  • tests/unit/supply_type_test.py
  • tests/unit/token_create_transaction_test.py
  • tests/unit/token_delete_transaction_test.py
  • tests/unit/token_fee_schedule_update_transaction_test.py
  • tests/unit/token_type_test.py
  • tests/unit/token_update_nfts_transaction_test.py
  • tests/unit/token_update_transaction_test.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions

Copy link
Copy Markdown

Hi, this is WorkflowBot.
Your pull request cannot be merged as it is not passing all our workflow checks.
Please click on each check to review the logs and resolve issues so all checks pass.
To help you:

Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
@manishdait
manishdait force-pushed the chore/token-lifecycle-from-protobuf branch from 6fa088f to 958449e Compare November 17, 2026 15:59
Signed-off-by: Manish Dait <daitmanish88@gmail.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8ea80da and 4a06dc8.

Files selected for processing: 4

  • tests/integration/token_delete_transaction_e2e_test.py
  • tests/integration/token_fee_schedule_update_transaction_e2e_test.py
  • tests/integration/token_update_nfts_transaction_e2e_test.py
  • tests/integration/token_update_transaction_e2e_test.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

.sign(fee_schedule_key)
)

copy_tx = TokenFeeScheduleUpdateTransaction.from_bytes(original_tx.to_bytes())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial · Maintainability & Code Quality · Quick win

Assert the reconstructed fields before execution.

execute() can submit restored _transaction_body_bytes without rebuilding the body from copy_tx. The network assertions can therefore pass even if _from_protobuf fails to restore token_id or custom_fees.

Before execution, assert copy_tx.token_id, the fee count, and the restored fee's type, amount, and collector. Keep the network assertions to verify execution separately.

As per path instructions, “Suggest additional assertions that would strengthen correctness.” This also targets the PR's field-for-field restoration objective.

Source: Path instructions

original_update_tx.transaction_fee = Hbar(3).to_tinybars()
original_update_tx.freeze_with(env.client).sign(metadata_private_key)

copy_update_tx = TokenUpdateNftsTransaction.from_bytes(original_update_tx.to_bytes())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trivial · Maintainability & Code Quality · Quick win

Assert the restored NFT update fields.

The restored transaction retains the original signed body bytes. Execution can submit those bytes even if _from_protobuf leaves token_id, serial_numbers, or metadata unset. The final metadata assertion does not detect that omission. (raw.githubusercontent.com)

After Line 295, compare those three attributes with nft_id, list(serials), and updated_metadata. Keep the signed execution and network assertions.

As per path instructions, “Suggest additional assertions that would strengthen correctness.”

Source: Path instructions

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Issue has been approved by team member lang: python Uses Python programming language open to community review PR is open for community review and feedback queue:junior-committer PR awaiting initial quality review skill: advanced requires knowledge of multiple areas in the codebase without defined steps to implement or examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: implement _from_protobuf for token lifecycle transactions (from_bytes round-trip)

3 participants